return function()
  local toggleterm = require('toggleterm')
  if require('core.global').is_windows then
    -- 使用powershell，换默认shell为powershell
    local powershell_options = {
      shell = vim.fn.executable('pwsh') == 1 and 'pwsh' or 'powershell',
      shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;',
      shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait',
      shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode',
      shellquote = '',
      shellxquote = '',
    }
    for option, value in pairs(powershell_options) do
      vim.opt[option] = value
    end
  end

  toggleterm.setup({
    function(term)
      if term.direction == 'horizontal' then
        return 15 -- 水平时高度
      elseif term.direction == 'vertical' then
        return vim.o.columns * 1 -- 垂直时宽度
      end
    end,
    open_mapping = [[<c-\>]], -- 打开终端
    hide_numbers = true, -- hide the number column in toggleterm buffers
    autochdir = true, -- when neovim changes it current directory the terminal will change it's own when next it's opened
    shell = vim.o.shell,
    direction = 'float', -- 终端展示的方式: 'vertical' | 'horizontal' | 'tab' | 'float',
    float_opts = {
      border = 'curved',
      winblend = 0,
    },
    winbar = {
      enabled = false,
      name_formatter = function(term) --  term: Terminal
        return term.name
      end,
    },
  })
end
